<?php

namespace App\Modules\Admin\Services\Mall;

use App\Exceptions\Exception;
use App\Modules\Admin\Entities\Mall\GoodsCateModel;
use App\Modules\Admin\Entities\Mall\GoodsModel;
use App\Modules\Admin\Entities\Mall\GoodsRuleModel;
use App\Modules\Admin\Entities\Water\WaterDeviceModel;
use App\Modules\Admin\Services\BaseService;
use Illuminate\Support\Facades\DB;

class GoodsRuleServices extends BaseService
{
    public function __construct(GoodsRuleModel $model)
    {
        $this->model = $model;
    }
    public function lists(array $params) : array
    {
        $params['where_callback'] = function($query) use ($params){
            $request = request();
            // 按照名称进行搜索
            if (!empty($search = $request->input('search', ''))){
                $query->where('goods_rule_name', 'LIKE', '%' . trim($search) . '%');
            }

        };

        return parent::lists($params); // TODO: Change the autogenerated stub
    }
    public function create(array $params)
    {

        DB::beginTransaction();
        try{
            parent::create($params); // TODO: Change the autogenerated stub
            DB::commit();
            return true;
        }catch (Exception $e){
            DB::rollBack();
            throw new Exception($e->getMessage());
        }
    }
    public function update(array $params)
    {

        DB::beginTransaction();
        try{
            parent::update($params); // TODO: Change the autogenerated stub
            DB::commit();
            return true;
        }catch (Exception $e){
            DB::rollBack();
            throw new Exception($e->getMessage());
        }
    }
    public function detail($request){

        return $request;
    }
}
